package leetcode_core.test;

import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * 功能描述
 *
 * @author: 张庭杰
 * @date: 2022年10月15日 15:40
 */
public class EchoHandler implements Runnable{
    private Socket client;
    public EchoHandler(Socket client){//主线程传递连接描述对象
        this.client = client;
    }
    @Override
    public void run() {
        try {
            Scanner scanner = new Scanner(client.getInputStream());
            PrintStream out = new PrintStream(client.getOutputStream());
            boolean flag = true;
            while (flag){
                if(scanner.hasNext()){
                    String value = KeyBoardInputUtils.getString("Input:");
                    if (value.equalsIgnoreCase("exit")) {
                        out.println("exit");
                        flag = false;
                    }else{
                        out.println(value);
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
